package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_bank_statement;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_bank_statementSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_bank_statementService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[银行对账单] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_bank_statementServiceImpl implements IAccount_bank_statementService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_bank_statementClientService account_bank_statementClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_bank_statement clientModel = account_bank_statementClientService.createModel();
        clientModel.setId(id);
        account_bank_statementClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Account_bank_statement account_bank_statement) {
        boolean bOk = false ;
        Iaccount_bank_statement clientModel = this.convert2Model(account_bank_statement,null);
        account_bank_statementClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_bank_statement);
        bOk = true ;

        return bOk ;
    }

    @Override
    public Account_bank_statement get(Integer id) {
        Iaccount_bank_statement clientModel = account_bank_statementClientService.createModel();
        clientModel.setId(id);
        account_bank_statementClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_bank_statement get(Account_bank_statement account_bank_statement) {
        Account_bank_statement retaccount_bank_statement = this.get(account_bank_statement.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_bank_statement.getClass(), account_bank_statement.getClass(), false);
        copier.copy(retaccount_bank_statement, account_bank_statement, null);
        return account_bank_statement ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_bank_statementClientService.removeBatch(account_bank_statements) ;

    }

    @Override
    public void updateBatch(List<Account_bank_statement> account_bank_statements, int batchSize) {

        //account_bank_statementClientService.updateBatch(account_bank_statements,batchSize) ;

    }

    @Override
    public void createBatch(List<Account_bank_statement> account_bank_statements, int batchSize) {

                        //account_bank_statementClientService.createBatch(account_bank_statements,batchSize) ;

    }

    @Override
    public boolean update(Account_bank_statement account_bank_statement) {
        boolean bOk = false ;
        Iaccount_bank_statement clientModel = this.convert2Model(account_bank_statement,null);
        account_bank_statementClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_bank_statement) ;
        bOk = true;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_bank_statement> searchDefault(Account_bank_statementSearchContext context) {
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据银行资金调节表查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_cashbox_end(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据银行资金调节表查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_cashbox_start(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据日记账查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_journal(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_company(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_create(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_user(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement> selectByOdoo_write(Integer id){
        Account_bank_statementSearchContext context = new Account_bank_statementSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement> list = new ArrayList<Account_bank_statement>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement> clientModelList = account_bank_statementClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_bank_statement convert2Model(Account_bank_statement domain , Iaccount_bank_statement model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_bank_statementClientService.createModel() ;
        }

         if(domain.getMessage_idsDirtyFlag())
            model.setMessage_ids(domain.getMessage_ids());
         if(domain.getMove_line_idsDirtyFlag())
            model.setMove_line_ids(domain.getMove_line_ids());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getBalance_end_realDirtyFlag())
            model.setBalance_end_real(domain.getBalance_end_real());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getPos_session_idDirtyFlag())
            model.setPos_session_id(domain.getPos_session_id());
         if(domain.getBalance_endDirtyFlag())
            model.setBalance_end(domain.getBalance_end());
         if(domain.getTotal_entry_encodingDirtyFlag())
            model.setTotal_entry_encoding(domain.getTotal_entry_encoding());
         if(domain.getDate_doneDirtyFlag())
            model.setDate_done(domain.getDate_done());
         if(domain.getMessage_channel_idsDirtyFlag())
            model.setMessage_channel_ids(domain.getMessage_channel_ids());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getAll_lines_reconciledDirtyFlag())
            model.setAll_lines_reconciled(domain.getAll_lines_reconciled());
         if(domain.getMessage_is_followerDirtyFlag())
            model.setMessage_is_follower(domain.getMessage_is_follower());
         if(domain.getWebsite_message_idsDirtyFlag())
            model.setWebsite_message_ids(domain.getWebsite_message_ids());
         if(domain.getMessage_needaction_counterDirtyFlag())
            model.setMessage_needaction_counter(domain.getMessage_needaction_counter());
         if(domain.getLine_idsDirtyFlag())
            model.setLine_ids(domain.getLine_ids());
         if(domain.getMessage_attachment_countDirtyFlag())
            model.setMessage_attachment_count(domain.getMessage_attachment_count());
         if(domain.getMessage_has_errorDirtyFlag())
            model.setMessage_has_error(domain.getMessage_has_error());
         if(domain.getMessage_unreadDirtyFlag())
            model.setMessage_unread(domain.getMessage_unread());
         if(domain.getMove_line_countDirtyFlag())
            model.setMove_line_count(domain.getMove_line_count());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getDateDirtyFlag())
            model.setDate(domain.getDate());
         if(domain.getIs_difference_zeroDirtyFlag())
            model.setIs_difference_zero(domain.getIs_difference_zero());
         if(domain.getMessage_unread_counterDirtyFlag())
            model.setMessage_unread_counter(domain.getMessage_unread_counter());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getMessage_main_attachment_idDirtyFlag())
            model.setMessage_main_attachment_id(domain.getMessage_main_attachment_id());
         if(domain.getMessage_needactionDirtyFlag())
            model.setMessage_needaction(domain.getMessage_needaction());
         if(domain.getMessage_has_error_counterDirtyFlag())
            model.setMessage_has_error_counter(domain.getMessage_has_error_counter());
         if(domain.getMessage_partner_idsDirtyFlag())
            model.setMessage_partner_ids(domain.getMessage_partner_ids());
         if(domain.getMessage_follower_idsDirtyFlag())
            model.setMessage_follower_ids(domain.getMessage_follower_ids());
         if(domain.getDifferenceDirtyFlag())
            model.setDifference(domain.getDifference());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getReferenceDirtyFlag())
            model.setReference(domain.getReference());
         if(domain.getBalance_startDirtyFlag())
            model.setBalance_start(domain.getBalance_start());
         if(domain.getAccounting_dateDirtyFlag())
            model.setAccounting_date(domain.getAccounting_date());
         if(domain.getUser_id_textDirtyFlag())
            model.setUser_id_text(domain.getUser_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getJournal_id_textDirtyFlag())
            model.setJournal_id_text(domain.getJournal_id_text());
         if(domain.getJournal_typeDirtyFlag())
            model.setJournal_type(domain.getJournal_type());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getAccount_idDirtyFlag())
            model.setAccount_id(domain.getAccount_id());
         if(domain.getCashbox_start_idDirtyFlag())
            model.setCashbox_start_id(domain.getCashbox_start_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getCashbox_end_idDirtyFlag())
            model.setCashbox_end_id(domain.getCashbox_end_id());
         if(domain.getUser_idDirtyFlag())
            model.setUser_id(domain.getUser_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Account_bank_statement convert2Domain( Iaccount_bank_statement model ,Account_bank_statement domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_bank_statement();
        }

        if(model.getMessage_idsDirtyFlag())
            domain.setMessage_ids(model.getMessage_ids());
        if(model.getMove_line_idsDirtyFlag())
            domain.setMove_line_ids(model.getMove_line_ids());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getBalance_end_realDirtyFlag())
            domain.setBalance_end_real(model.getBalance_end_real());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getPos_session_idDirtyFlag())
            domain.setPos_session_id(model.getPos_session_id());
        if(model.getBalance_endDirtyFlag())
            domain.setBalance_end(model.getBalance_end());
        if(model.getTotal_entry_encodingDirtyFlag())
            domain.setTotal_entry_encoding(model.getTotal_entry_encoding());
        if(model.getDate_doneDirtyFlag())
            domain.setDate_done(model.getDate_done());
        if(model.getMessage_channel_idsDirtyFlag())
            domain.setMessage_channel_ids(model.getMessage_channel_ids());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getAll_lines_reconciledDirtyFlag())
            domain.setAll_lines_reconciled(model.getAll_lines_reconciled());
        if(model.getMessage_is_followerDirtyFlag())
            domain.setMessage_is_follower(model.getMessage_is_follower());
        if(model.getWebsite_message_idsDirtyFlag())
            domain.setWebsite_message_ids(model.getWebsite_message_ids());
        if(model.getMessage_needaction_counterDirtyFlag())
            domain.setMessage_needaction_counter(model.getMessage_needaction_counter());
        if(model.getLine_idsDirtyFlag())
            domain.setLine_ids(model.getLine_ids());
        if(model.getMessage_attachment_countDirtyFlag())
            domain.setMessage_attachment_count(model.getMessage_attachment_count());
        if(model.getMessage_has_errorDirtyFlag())
            domain.setMessage_has_error(model.getMessage_has_error());
        if(model.getMessage_unreadDirtyFlag())
            domain.setMessage_unread(model.getMessage_unread());
        if(model.getMove_line_countDirtyFlag())
            domain.setMove_line_count(model.getMove_line_count());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getDateDirtyFlag())
            domain.setDate(model.getDate());
        if(model.getIs_difference_zeroDirtyFlag())
            domain.setIs_difference_zero(model.getIs_difference_zero());
        if(model.getMessage_unread_counterDirtyFlag())
            domain.setMessage_unread_counter(model.getMessage_unread_counter());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getMessage_main_attachment_idDirtyFlag())
            domain.setMessage_main_attachment_id(model.getMessage_main_attachment_id());
        if(model.getMessage_needactionDirtyFlag())
            domain.setMessage_needaction(model.getMessage_needaction());
        if(model.getMessage_has_error_counterDirtyFlag())
            domain.setMessage_has_error_counter(model.getMessage_has_error_counter());
        if(model.getMessage_partner_idsDirtyFlag())
            domain.setMessage_partner_ids(model.getMessage_partner_ids());
        if(model.getMessage_follower_idsDirtyFlag())
            domain.setMessage_follower_ids(model.getMessage_follower_ids());
        if(model.getDifferenceDirtyFlag())
            domain.setDifference(model.getDifference());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getReferenceDirtyFlag())
            domain.setReference(model.getReference());
        if(model.getBalance_startDirtyFlag())
            domain.setBalance_start(model.getBalance_start());
        if(model.getAccounting_dateDirtyFlag())
            domain.setAccounting_date(model.getAccounting_date());
        if(model.getUser_id_textDirtyFlag())
            domain.setUser_id_text(model.getUser_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getJournal_id_textDirtyFlag())
            domain.setJournal_id_text(model.getJournal_id_text());
        if(model.getJournal_typeDirtyFlag())
            domain.setJournal_type(model.getJournal_type());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getAccount_idDirtyFlag())
            domain.setAccount_id(model.getAccount_id());
        if(model.getCashbox_start_idDirtyFlag())
            domain.setCashbox_start_id(model.getCashbox_start_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getCashbox_end_idDirtyFlag())
            domain.setCashbox_end_id(model.getCashbox_end_id());
        if(model.getUser_idDirtyFlag())
            domain.setUser_id(model.getUser_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
